package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Lenovo
 * @date 2025年09月06日 10:33
 */
@RestController
public class DataController {
    @Autowired
    private DataService dataService;
    
    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONArray data = new JSONArray();
        retult.put("data",data);


        List<Map<String, Object>> maps = dataService.select1();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name","第二大类交易额排名");
            row.put("value",map.get("cta"));
            data.add(row);
        }
        return retult;
    }

    @RequestMapping("/s2")
    public JSONObject select2() {
        JSONObject retult = new JSONObject();
        retult.put("status", 0);
        retult.put("msg", "");
        JSONObject data = new JSONObject();
        retult.put("data", data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();
        data.put("categories",categories);
        data.put("series",series);

        JSONObject col1 = new JSONObject();
        col1.put("name","品牌交易额排名");
        series.add(col1);
        JSONArray col1_data = new JSONArray();
        col1.put("data",col1_data);


        List<Map<String, Object>> maps = dataService.select2();
        for (Map<String, Object> map : maps) {
            categories.add(map.get("name"));
            col1_data.add(map.get("cta"));
        }

        return retult;
    }

    @RequestMapping("/s3")
    public JSONObject select3() {
        JSONObject retult = new JSONObject();
        retult.put("status", 0);
        retult.put("msg", "");
        JSONObject data = new JSONObject();
        retult.put("data", data);
        List<Map<String, Object>> maps = dataService.select3();
        Map<String, Object> map = maps.get(0);
        data.put("data",map.get("cta"));


        return retult;
    }

    @RequestMapping("/s4")
    public JSONObject select4() {
        JSONObject retult = new JSONObject();
        retult.put("status", 0);
        retult.put("msg", "");
        JSONObject data = new JSONObject();
        retult.put("data", data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);
        JSONObject col1 = new JSONObject();
        col1.put("name","订单金额");
        col1.put("id","name");
        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","订单金额");
        col2.put("id","cta");
        columns.add(col2);

        List<Map<String,Object>>maps=dataService.select4();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            rows.add(row);

        }
        return retult;
    }
}
